import java.util.Scanner;

public class CalendarSeeker {

	public static enum Month {
		JANUARY((byte)31),
		FEBRUARY((byte)28),
		MARCH((byte)31),
		APRIL((byte)30),
		MAY((byte)31),
		JUNE((byte)30),
		JULY((byte)31),
		AUGUST((byte)31),
		SEPTEMBER((byte)30),
		OCTOBER((byte)31),
		NOVEMBER((byte)30),
		DECEMBER((byte)31);
		
		Month(byte daysCount) {
			DAYS_COUNT = daysCount;
		}
		
		public final byte DAYS_COUNT;
		
		public static final byte COUNT = 12;
	}

	public static enum DayOfWeek {
		SUNDAY,
		MONDAY,
		TUESDAY,
		WEDNESDAY,
		THURSDAY,
		FRIDAY,
		SATURDAY
	}
	
	public static boolean isValidDate(byte day, byte month, short year) {
	
	    if (month < 1 || month > Month.COUNT || year < 0) return false;

		byte maxDaysInMonth = Month.values()[month-1].DAYS_COUNT;
		
		if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ) ++maxDaysInMonth; 
		
		if(day < 1 || day > maxDaysInMonth) return false;
		
		return true;
	}
	
	public static DayOfWeek getDayOfWeekOf(byte day, byte month, short year) throws IllegalArgumentException {
		
		if(!isValidDate(day, month, year)) throw new IllegalArgumentException("is not a valid date!");
		
		// год начинается с марта
		month -= 2;
		if (month <= 0) {
			month += 12;
			--year;
		}
		
		// собственно формула
		int n = (day + (13 * month - 1) / 5 + (year % 100) + (year / 100) / 4 + (year % 100) / 4 - 2 * (year / 100)) % 7;
		
		// если получается число < 0, то прибавляем 7
		if (n < 0) {
			n += 7;
		};
		
		return DayOfWeek.values()[n];	
	}
	
	public static void main (String[] args) {
		Scanner input = new Scanner(System.in);
		
		byte day;
		byte month;
		short year;
		
		System.out.print("Enter day: ");
		day = input.nextByte();
		
		System.out.print("Enter month: ");
		month = input.nextByte();
		
		System.out.print("Enter year: ");
		year = input.nextShort();
		try {
			System.out.println(getDayOfWeekOf(day, month, year));
		}
		catch(IllegalArgumentException e) {
			System.out.println(e);
		}
	}

}